package com.linjiahao.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linjiahao.userservice.entity.Friends;
import com.linjiahao.userservice.entity.FriendsAsk;
import com.linjiahao.userservice.entity.UcenterMember;
import com.linjiahao.userservice.mapper.FriendsMapper;
import com.linjiahao.userservice.service.FriendsAskService;
import com.linjiahao.userservice.service.FriendsService;
import com.linjiahao.userservice.service.UcenterMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-10-27
 */
@Service
public class FriendsServiceImpl extends ServiceImpl<FriendsMapper, Friends> implements FriendsService {

    @Autowired
    FriendsAskService friendsAskService;

    @Autowired
    UcenterMemberService ucenterMemberService;

    @Override
    public boolean saveOne(Friends friends) {
        int insert = this.baseMapper.insert(friends);
        if(insert==1){
            boolean get_id = friendsAskService.remove(new QueryWrapper<FriendsAsk>().eq("get_id", friends.getId()));
            return true;
        }
        return false;
    }

    @Override
    public List<UcenterMember> getFreindList(String memberIdByJwtToken) {
        List<Friends> friendsList = this.baseMapper.selectList(new QueryWrapper<Friends>().eq("friend_id", memberIdByJwtToken));
        List<UcenterMember> ucenterMemberList=new ArrayList<>();
        for (Friends f:friendsList) {
            UcenterMember one = ucenterMemberService.getOne(new QueryWrapper<UcenterMember>().eq("id", f.getId()));
            ucenterMemberList.add(one);
        }
        return ucenterMemberList;

    }


}
